Learning Perl by Randal L. Schwartz & Tom Phoenix & brian d foy
Author:Randal L. Schwartz & Tom Phoenix & brian d foy [Randal L. Schwartz]
Language: eng
Format: epub
Tags: COMPUTERS / Programming Languages / JavaScript
ISBN: 9780596551858
Publisher: O'Reilly Media
Published: 2009-03-04T16:00:00+00:00
* * *
[‡] Well, to be sure, he did leave out the ones that have no use in Perl, such as the operator that turns a number into the memory address of a variable. And he added several operators (like the string concatenation operator) that make C folks jealous of Perl.
Logical Operators
As you might expect, Perl has all of the necessary logical operators needed to work with Boolean (true/false) values. For example, it’s often useful to combine logical tests by using the logical AND operator (&&) and the logical OR operator (||):
if ($dessert{'cake'} && $dessert{'ice cream'}) { # Both are true print "Hooray! Cake and ice cream!\n"; } elsif ($dessert{'cake'} || $dessert{'ice cream'}) { # At least one is true print "That's still good...\n"; } else { # Neither is true - do nothing (we're sad) }
There may be a shortcut. If the left side of a logical AND operation is false, the whole thing is false, since logical AND needs both sides to be true in order to return true. In that case, there’s no reason to check the right side, so it will not even be evaluated. Consider what happens in this example if $hour is 3:
if ( (9 <= $hour) && ($hour < 17) ) { print "Aren't you supposed to be at work...?\n"; }
Similarly, if the left side of a logical OR operation is true, the right side will not be evaluated. Consider what happens here if $name is fred:
if ( ($name eq 'fred') || ($name eq 'barney') ) { print "You're my kind of guy!\n"; }
Because of this behavior, these operators are called “short-circuit” logical operators. They take a short circuit to the result whenever they can. In fact, it’s fairly common to rely upon this short-circuit behavior. Suppose you need to calculate an average:
if ( ($n != 0) && ($total/$n < 5) ) { print "The average is below five.\n"; }
In that example, the right side will be evaluated only if the left side is true, so we can’t accidentally divide by zero and crash the program.
Download
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.
Coding Theory | Localization |
Logic | Object-Oriented Design |
Performance Optimization | Quality Control |
Reengineering | Robohelp |
Software Development | Software Reuse |
Structured Design | Testing |
Tools | UML |
Deep Learning with Python by François Chollet(12518)
Hello! Python by Anthony Briggs(9865)
OCA Java SE 8 Programmer I Certification Guide by Mala Gupta(9755)
The Mikado Method by Ola Ellnestam Daniel Brolund(9745)
Dependency Injection in .NET by Mark Seemann(9291)
Algorithms of the Intelligent Web by Haralambos Marmanis;Dmitry Babenko(8256)
Test-Driven iOS Development with Swift 4 by Dominik Hauser(7739)
Grails in Action by Glen Smith Peter Ledbrook(7665)
The Well-Grounded Java Developer by Benjamin J. Evans Martijn Verburg(7514)
Becoming a Dynamics 365 Finance and Supply Chain Solution Architect by Brent Dawson(6739)
Microservices with Go by Alexander Shuiskov(6503)
Practical Design Patterns for Java Developers by Miroslav Wengner(6404)
Test Automation Engineering Handbook by Manikandan Sambamurthy(6381)
Secrets of the JavaScript Ninja by John Resig Bear Bibeault(6376)
Angular Projects - Third Edition by Aristeidis Bampakos(5759)
The Art of Crafting User Stories by The Art of Crafting User Stories(5292)
NetSuite for Consultants - Second Edition by Peter Ries(5236)
Demystifying Cryptography with OpenSSL 3.0 by Alexei Khlebnikov(5052)
Kotlin in Action by Dmitry Jemerov(5017)
